<?php
/*
 +----------------------------------------------------------------------
 + Title        : OCR 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2021/8/28 16:36
 + Last-time    : 2021/8/28 16:36+ chen2
 + Desc         : OCR
 +----------------------------------------------------------------------
*/


namespace aliyun;

use utils\ExtendHttp;

class OCR
{
    const OCI_URL  = 'http://jisusfzsb.market.alicloudapi.com/idcardrecognition/recognize';
    const TYPE_URL = 'http://jisusfzsb.market.alicloudapi.com/idcardrecognition/type';

    public static function run($pic)
    {
        $query['typeid'] = '2';
        $query['appcode'] = config('oci.AppCode');
        $url = self::OCI_URL;
        $data['pic'] = $pic;
        $options['query'] = $query;
        $options['headers'][] = "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8";
        $options['headers'][] = "Authorization:APPCODE " . config('oci.AppCode');
        $res = ExtendHttp::post($url, $data, $options);
        $result = json_decode($res, true);
        if (!$result) {
            error_abort('身份证图片识别异常~');
        }
        if ($result['status'] !== 0) {
            error_abort($result['msg']);
        }
        return $result['result'];
    }
}